package com.home.cop.system;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler{

    private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(RuntimeException.class)
    public Result runtimeExceptionHandler(RuntimeException e) {
        Result result = new Result();
        result.setMessage("系统错误，请联系管理员");
        result.setSuccess(false);
        logger.error(e.getMessage());
        return result;
    }

    @ExceptionHandler(BusinessException.class)
    public Result BusinessHandler(BusinessException e) {
        Result result = new Result();
        result.setMessage(e.getMessage());
        result.setSuccess(false);
        return result;
    }
}
